package com.football.springboot.controller;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.update.Update;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.football.springboot.common.Constants;
import com.football.springboot.entity.*;
import com.football.springboot.mapper.PositionMapper;
import com.football.springboot.service.*;
import com.football.springboot.vo.PlayerQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.football.springboot.common.Return;
import com.football.springboot.common.Result;
//导入service
//导入entity

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李越
 * @since 2023-02-24
 */
@Api(tags = "球员管理")
@RestController
@RequestMapping("/player")
public class PlayerController {

    @Resource
    private IPlayerService playerService;

    @Resource
    private PositionMapper positionMapper;

    @Resource
    private IPlayerAbilityService playerAbilityService;

    @Resource
    private IPlayerDataSingleService playerDataSingleService;

    @Resource
    private IGameService gameService;

    @Resource
    private IGameDataService gameDataService;

    @Resource
    private ITeamService teamService;

    @Resource
    private IPlayerDataService playerDataService;


    @Resource
    private ILeagueService leagueService;

    // 新增或者更新
    @ApiOperation("新增或者更新")
    @PostMapping("/saveOrUpdate")
    public Result save(@RequestBody Player player) {
        //添加球员时,计算球队身价
        Team team=teamService.getById(player.getTeamId());
        //新增球员时 加上球队身价
        if (!player.equals(playerService.getById(player.getId()))){
            team.setTeamValue((team.getTeamValue()==null?0:team.getTeamValue())+player.getPlayerValue());
        }else{//修改球员时 修改球队身价
            team.setTeamValue((team.getTeamValue()==null?0:team.getTeamValue())-playerService.getById(player.getId()).getPlayerValue()+player.getPlayerValue());
        }
        playerService.saveOrUpdate(player);
        return Result.success();
    }


    //删除
    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        playerService.removeById(id);
        return Result.success();
    }

    //批量删除
    @ApiOperation("批量删除")
    @PostMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        playerService.removeByIds(ids);
        return Result.success();
    }

    //查询全部
    @ApiOperation("查询全部")
    @GetMapping("/findall")
    public Result findAll() {
        return Result.success(playerService.list());
    }

    //根据id查找
    @ApiOperation("根据id查找")
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(playerService.getById(id));
    }


    //后台管理分页查询
    @ApiOperation("分页查询")
    @GetMapping("/pagePlayer")
    public Return pagePlayer(@RequestParam Integer current,
                             @RequestParam Integer limit,
                             PlayerQueryVo playerQueryVo) {

        //创建page对象,传递当前页数current,每页记录数limit
        Page<Player> page = new Page<>(current,limit);
        //构建条件 模糊查询
        QueryWrapper<Player> queryWrapper = new QueryWrapper<>();
        String playerName = playerQueryVo.getPlayerName();
        String playerPosition = playerQueryVo.getPlayerPosition();
        Integer teamId = playerQueryVo.getTeamId();
        Long playerValue = playerQueryVo.getPlayerValue();
        Long playerMaxValue = playerQueryVo.getPlayerMaxValue();

        Long playerMinValue = playerQueryVo.getPlayerMinValue();


        //根据球员名称查询
        if(!StringUtils.isEmpty(playerName)){
            queryWrapper.like("player_name",playerName);
        }
        //根据所属球队查询
        queryWrapper.eq(teamId!=null,"team_id",teamId);

        //根据球员场上位置查询
        if(!StringUtils.isEmpty(playerPosition)){
            queryWrapper.like("player_position",playerPosition);
        }

        //根据球员身价查询
        queryWrapper.between(playerMaxValue!=null && playerMinValue!=null,"player_value",playerMinValue,playerMaxValue);
        queryWrapper.le(playerMaxValue!=null,"player_value",playerMaxValue);
        queryWrapper.ge(playerMinValue!=null,"player_value",playerMinValue);
        queryWrapper.eq(playerValue!=null,"player_value",playerValue);


        queryWrapper.orderByDesc("id");
        Page<Player> pagePlayer = playerService.page(page,queryWrapper);
        List<Player> records = pagePlayer.getRecords();
        System.out.println(records);

        records.forEach(player -> {
            //将所属球队信息插入到列表中
            player.setTeam(playerService.getTeaminfoByplayer(player.getId()));
        });

        return Return.ok().put("pagePlayer",pagePlayer).put("total",pagePlayer.getTotal());
    }







    //获取所有场上位置
    @ApiOperation("获取所有场上位置")
    @GetMapping("/position")
    public Result getPosition(){
        QueryWrapper<Position> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", Constants.POSITION_TYPE);
        return Result.success(positionMapper.selectList(queryWrapper));
    }

    //获取球员能力值
    @ApiOperation("获取球员能力值")
    @GetMapping("/getPlayerAbility")
    public Result getPlayerAbility(@RequestParam Integer playerId){
        return Result.success(playerService.getPlayerAbility(playerId));
    }

    //编辑球员能力值
    @ApiOperation("编辑球员能力值")
    @PostMapping("/saveAbility")
    public Result saveAbility(@RequestBody PlayerAbility playerAbility,
                              @RequestParam Integer playerId){
        //把playerId关联给球员能力表的player_id
        playerAbility.setPlayerId(playerId);
        System.out.println(playerAbility);
        UpdateWrapper<PlayerAbility> updateWrapper = new UpdateWrapper<>();

        QueryWrapper<PlayerAbility> queryWrapper = new QueryWrapper<>();
        if (playerAbilityService.getOne(queryWrapper.eq("player_id",playerAbility.getPlayerId()))==null){
            return Result.success(playerAbilityService.save(playerAbility));
        }else{
            return Result.success(playerAbilityService.update(playerAbility,updateWrapper.eq("player_id",playerId)));
        }
    }


    //根据比赛id查出双方球队
    @ApiOperation("根据比赛id查出两方球队")
    @GetMapping("/getTeamByGameId")
    public Result getTeamByGameId(@RequestParam Integer gameId){

        List<Integer> ids = new ArrayList<>();
        Game game = gameService.getById(gameId);
        ids.add(game.getHomeTeam());
        ids.add(game.getAwayTeam());
        return Result.success(teamService.listByIds(ids));
    }


    //根据球队id查出该球队的所有球员
    @ApiOperation("根据球队id查出该球队的所有球员")
        @GetMapping("/getPlayerByTeamId/{teamId}")
    public Result getPlayerByTeamId(@PathVariable Integer teamId){
        return Result.success(playerService.getPlayerByTeamId(teamId));
    }

    //查看球员单场数据
    @ApiOperation("查看球员单场数据")
    @GetMapping("/getPlayerData")
    public Result getPlayerData(@RequestParam Integer gameId,
                                @RequestParam Integer playerId
                                ){
        //选择球员后再查看
        //根据game_id和player_id查询出一个球员单场数据
        PlayerDataSingle playerDataSingle = playerDataSingleService.getPlayerDataSingle(playerId,gameId);
        if (playerId!=null){
            playerDataSingle.setPlayer(playerService.getById(playerId));
        }
        return Result.success(playerDataSingle);
    }




    //编辑球员单场数据（会同时编辑球员的赛季数据 ）
    @ApiOperation("编辑球员单场数据")
    @PostMapping("/savePlayerDataSingle")
    public Result savePlayerDataSingle(@RequestBody PlayerDataSingle playerDataSingle,
                                       @RequestParam Integer playerId,
                                       @RequestParam Integer gameId){
        //把gameId、playerId关联给球员单场数据表的game_id和player_id
        //这两个字段可以确保这一行数据的唯一性
        playerDataSingle.setGameId(gameId);
        playerDataSingle.setPlayerId(playerId);
        playerDataSingle.setTeamId(playerService.getById(playerId).getTeamId());
        System.out.println(playerDataSingle);

        QueryWrapper<PlayerDataSingle> queryWrappersingle=new QueryWrapper<>();
        UpdateWrapper<PlayerDataSingle> updateWrappersingle = new UpdateWrapper<>();
        QueryWrapper<PlayerData> queryWrapperplayer = new QueryWrapper<>();
        UpdateWrapper<PlayerData> updateWrapperplayer = new UpdateWrapper<>();
        UpdateWrapper<PlayerData> updateWrapperplayerexist = new UpdateWrapper<>();

        //球员单场数据表里没有就新增 有就修改
        if (playerDataSingleService.getOne(queryWrappersingle
                .eq("game_id",gameId)
                .eq("player_id",playerId))==null){
            //新增球员赛季数据
            if (playerDataService.getOne(queryWrapperplayer
                    .eq("player_id",playerId)
                    .eq("team_id",playerService.getById(playerId).getTeamId())
            .eq("league_id",gameService.getById(gameId).getLeagueId()))==null){//球员赛季数据行未创建时
            PlayerData playerData = playerDataService.addplayerdata(playerDataSingle);
            playerDataService.save(playerData);
            }else{
            //更新已经存在的球员赛季数据行 修改数据行
            //先找到那一行数据
            PlayerData updateplayerdata = playerDataService.getupdateplayerdata(playerId,gameService.getById(gameId).getLeagueId());
            PlayerData playerData = playerDataService.updateplayerdata(updateplayerdata,playerDataSingle);
            playerDataService.update(playerData,updateWrapperplayer
                    .eq("player_id",playerId)
                    .eq("league_id",gameService.getById(gameId).getLeagueId()));
            }


            //新增球员单场数据表
            return Result.success(playerDataSingleService.save(playerDataSingle));
        }else{
            //先找出修改前的球员单场比赛数据(要先获取没修改之前球员单场比赛的数据，才能统计赛季数据)
            PlayerDataSingle playerDataSinglebefore = playerDataSingleService.getPlayerDataSingle(playerId,gameId);
            //修改球员单场比赛数据时更新该球员的赛季数据
            PlayerData updateplayerdata=playerDataService.getupdateplayerdata(playerId,gameService.getById(gameId).getLeagueId());
            PlayerData playerData=playerDataService.updateplayerdataexist(updateplayerdata,playerDataSinglebefore,playerDataSingle);
            playerDataService.update(playerData,updateWrapperplayerexist
                    .eq("player_id",playerId)
                    .eq("league_id",gameService.getById(gameId).getLeagueId()));


            //修改球员单场数据表
            return Result.success(playerDataSingleService.update(playerDataSingle,updateWrappersingle
                    .eq("game_id",gameId)
                    .eq("player_id",playerId)));
        }
    }

    //导出球员接口
    @ApiOperation("导出球员接口")
    @GetMapping(value = "/export")
    public void export(HttpServletResponse response) throws Exception{
        //从数据库中查询所有球员数据
        List<Player> list = playerService.list();
        //写出到浏览器
        ExcelWriter writer = ExcelUtil.getWriter(true);

        //自定义标题名
        writer.addHeaderAlias("playerName","球员姓名");
        writer.addHeaderAlias("playerAge","球员年龄");
        writer.addHeaderAlias("playerImg","球员图片");
        writer.addHeaderAlias("playerHeight","球员身高");
        writer.addHeaderAlias("playerWeight","球员体重");
        writer.addHeaderAlias("playerPosition","场上位置");
        writer.addHeaderAlias("playerNumber","球衣号码");
        writer.addHeaderAlias("playerNation","球员国籍");
        writer.addHeaderAlias("playerValue","球员身价");

        //一次性写出list内的对象到excel,使用默认样式，强制输出标题
        writer.write(list,true);

        // 设置浏览器响应的格式
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        String fileName = URLEncoder.encode("球员信息", "UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");

        ServletOutputStream out = response.getOutputStream();
        writer.flush(out, true);
        out.close();
        writer.close();
    }

    //导入球员接口
    @ApiOperation("导入球员接口")
    @PostMapping(value = "/import")
    public Return imp(MultipartFile file) throws Exception {
        InputStream inputStream = file.getInputStream();
        ExcelReader reader = ExcelUtil.getReader(inputStream);

        //忽略表头的中文，直接读取表的内容
        List<List<Object>> list = reader.read(1);
        List<Player> players = CollUtil.newArrayList();
        for (List<Object> row : list) {
            Player player = new Player();
            player.setPlayerName(row.get(1).toString());
            player.setPlayerAge(Integer.parseInt(row.get(2).toString()));
            player.setPlayerImg(row.get(3).toString());
            player.setPlayerHeight(Double.valueOf(row.get(4).toString()));
            player.setPlayerWeight(Double.valueOf(row.get(5).toString()));
            player.setPlayerPosition(row.get(6).toString());
            player.setPlayerNumber(Integer.parseInt(row.get(7).toString()));
            player.setPlayerNation(row.get(8).toString());
            player.setPlayerValue(Long.valueOf(row.get(9).toString()));
            players.add(player);
        }

        playerService.saveBatch(players);
        return Return.ok();
    }

    //导出球员的能力接口
    @ApiOperation("导出球员的能力接口")
    @GetMapping(value = "/ability/export")
    public void exportability(HttpServletResponse response) throws Exception{
        //从数据库中查询所有球员能力数据
        List<PlayerAbility> list = playerAbilityService.list();
        //写出到浏览器
        ExcelWriter writer = ExcelUtil.getWriter(true);

        //自定义标题名
        writer.addHeaderAlias("capability","球员综合能力");
        writer.addHeaderAlias("attack","球员进攻");
        writer.addHeaderAlias("defense","球员防守");
        writer.addHeaderAlias("speed","球员速度");
        writer.addHeaderAlias("power","球员力量");
        writer.addHeaderAlias("shoot","球员射门");
        writer.addHeaderAlias("pass","球员传球");
        writer.addHeaderAlias("dribble","球员盘带");
        writer.addHeaderAlias("technique","球员技巧");
        writer.addHeaderAlias("freekick","球员任意球");
        writer.addHeaderAlias("stamina","球员体能");
        writer.addHeaderAlias("header","球员头球");
        writer.addHeaderAlias("jump","球员弹跳");
        writer.addHeaderAlias("keeper","球员守门");
        writer.addHeaderAlias("teamwork","球员团队合作");
        writer.addHeaderAlias("habitual","球员惯用脚");
        writer.addHeaderAlias("playerId","球员id");

        //一次性写出list内的对象到excel,使用默认样式,强制输出标题
        writer.write(list,true);

        //设置浏览器响应的格式
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        String fileName = URLEncoder.encode("球员能力信息", "UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");

        ServletOutputStream out = response.getOutputStream();
        writer.flush(out, true);
        out.close();
        writer.close();

    }

    //导入球员的能力接口
    @ApiOperation("导入球员的能力接口")
    @PostMapping(value = "/ability/import")
    public Return importability(MultipartFile file) throws Exception{
        InputStream inputStream = file.getInputStream();
        ExcelReader reader = ExcelUtil.getReader(inputStream);

        //忽略表头的中文，直接读取表的内容
        List<List<Object>> list = reader.read(1);
        List<PlayerAbility> playerAbilities = CollUtil.newArrayList();
        for (List<Object> row : list){
            PlayerAbility playerAbility = new PlayerAbility();
            playerAbility.setCapability(Integer.parseInt(row.get(0).toString()));
            playerAbility.setAttack(Integer.parseInt(row.get(1).toString()));
            playerAbility.setDefense(Integer.parseInt(row.get(2).toString()));
            playerAbility.setSpeed(Integer.parseInt(row.get(3).toString()));
            playerAbility.setPower(Integer.parseInt(row.get(4).toString()));
            playerAbility.setShoot(Integer.parseInt(row.get(5).toString()));
            playerAbility.setPass(Integer.parseInt(row.get(6).toString()));
            playerAbility.setDribble(Integer.parseInt(row.get(7).toString()));
            playerAbility.setTechnique(Integer.parseInt(row.get(8).toString()));
            playerAbility.setFreekick(Integer.parseInt(row.get(9).toString()));
            playerAbility.setStamina(Integer.parseInt(row.get(10).toString()));
            playerAbility.setHeader(Integer.parseInt(row.get(11).toString()));
            playerAbility.setJump(Integer.parseInt(row.get(12).toString()));
            playerAbility.setKeeper(Integer.parseInt(row.get(13).toString()));
            playerAbility.setTeamwork(Integer.parseInt(row.get(14).toString()));
            playerAbility.setHabitual(row.get(15).toString());
            playerAbility.setPlayerId(Integer.parseInt(row.get(16).toString()));
            playerAbilities.add(playerAbility);

        }
        playerAbilityService.saveBatch(playerAbilities);
        return Return.ok();
    }

    //前台查询球员列表
    @ApiOperation("前台查询球员列表")
    @GetMapping("/front/playerList")
    public Return playerList(@RequestParam Integer current,
                             @RequestParam Integer limit,PlayerQueryVo playerQueryVo){

        //创建page对象,传递当前页数current,每页记录数limit
        Page<Player> page = new Page<>(current,limit);
        QueryWrapper<Player> queryWrapper = new QueryWrapper<>();
        String playerName = playerQueryVo.getPlayerName();
        String playerPosition = playerQueryVo.getPlayerPosition();
        Integer teamId = playerQueryVo.getTeamId();
        Long playerValue = playerQueryVo.getPlayerValue();
        Long playerMaxValue = playerQueryVo.getPlayerMaxValue();

        Long playerMinValue = playerQueryVo.getPlayerMinValue();

        //根据球员名称查询
        if(!StringUtils.isEmpty(playerName)){
            queryWrapper.like("player_name",playerName);
        }
        //根据所属球队查询
        queryWrapper.eq(teamId!=null,"team_id",teamId);

        //根据球员场上位置查询
        if(!StringUtils.isEmpty(playerPosition)){
            queryWrapper.like("player_position",playerPosition);
        }

        //根据球员身价查询
        queryWrapper.between(playerMaxValue!=null && playerMinValue!=null,"player_value",playerMinValue,playerMaxValue);
        queryWrapper.le(playerMaxValue!=null,"player_value",playerMaxValue);
        queryWrapper.ge(playerMinValue!=null,"player_value",playerMinValue);
        queryWrapper.eq(playerValue!=null,"player_value",playerValue);
        //创建page对象,传递当前页数current,每页记录数limit
        Page<Player> pagePlayer = playerService.page(page,queryWrapper);
        List<Player> players = pagePlayer.getRecords();
        players.forEach(player -> {
            //插入球员所有联赛的总数据
            QueryWrapper<PlayerData> queryWrapperpd = new QueryWrapper<>();
            queryWrapperpd.eq("player_id",player.getId());
            List<PlayerData> playerDataList = playerDataService.list(queryWrapperpd);
            PlayerData playerDataall=new PlayerData();
            playerDataall=playerDataService.playerDataallleague(playerDataList,playerDataall);
            System.err.println(playerDataall);
            player.setPlayerData(playerDataall);
            //插入球员能力
            QueryWrapper<PlayerAbility> queryWrapperpa = new QueryWrapper<>();
            queryWrapperpa.eq("player_id",player.getId());
            player.setPlayerAbility(playerAbilityService.getOne(queryWrapperpa));
            player.setTeam(teamService.getById(player.getTeamId()));
        });

        return Return.ok().put("pagePlayer",pagePlayer).put("total",pagePlayer.getTotal());
    }

    //前台查看单个球员详细资料(包括球员能力)
    @ApiOperation("前台查看单个球员详细资料")
    @GetMapping("/front/getplayerbyid")
    public Result getplayerid(@RequestParam Integer playerId){
        //球员信息
        Player player = playerService.getById(playerId);
        //球员能力
        QueryWrapper<PlayerAbility> queryWrapperpa = new QueryWrapper<>();
        queryWrapperpa.eq("player_id",playerId);
        PlayerAbility playerAbility=playerAbilityService.getOne(queryWrapperpa);
        player.setPlayerAbility(playerAbility);
        //球员所属球队信息
        player.setTeam(teamService.getById(player.getTeamId()));


        return Result.success(player);
    }

    //获取一个球员参加的联赛
    @ApiOperation("获取一个球员参加的联赛")
    @GetMapping("/front/getplayerleague")
    public Result getplayerleague(@RequestParam Integer playerId){
        Player player=playerService.getById(playerId);
        List<League> leagueList = teamService.getLeagueByTeamId(player.getTeamId());

        return Result.success(leagueList);
    }


    //前台查看单个球员在不同联赛的赛季数据（包括球员全部联赛的总计）
    @ApiOperation("前台查看单个球员在不同联赛的赛季数据")
    @GetMapping("/front/getplayerdata")
    public Result getplayerdata(@RequestParam Integer playerId,@RequestParam Integer leagueId) {
        //球员赛季数据
        PlayerData playerData = new PlayerData();
        System.err.println("初始化：" + playerData);
        QueryWrapper<PlayerData> queryWrapperpd = new QueryWrapper<>();
        if (leagueId != null) {//查出单个联赛球员数据
            System.err.println("查出单个联赛球员数据");
            queryWrapperpd.eq("league_id", leagueId);
            queryWrapperpd.eq("player_id", playerId);
            playerData = playerDataService.getOne(queryWrapperpd);
            playerDataService.countplayerleague(playerData);
            return Result.success(playerData);
        } else {//查出所有联赛的球员数据和
            System.err.println("查出所有联赛的球员数据和");
            QueryWrapper<PlayerData> queryWrapperpds = new QueryWrapper<>();
            queryWrapperpds.eq("player_id", playerId);
            List<PlayerData> playerDataList = playerDataService.list(queryWrapperpds);
            PlayerData playerDataall = new PlayerData();
            playerDataall = playerDataService.playerDataallleague(playerDataList, playerDataall);
            playerDataService.countplayerleague(playerDataall);
            return Result.success(playerDataall);
        }
    }
    //前台查看单个球员赛程（包括单场比赛的球员详细数据）
    @ApiOperation("前台查看单个球员的赛程")
    @GetMapping("/front/getplayergame")
    public Result getplayergame(@RequestParam Integer playerId,@RequestParam Integer leagueId){
        QueryWrapper<Game> queryWrapperhome = new QueryWrapper<>();
        QueryWrapper<Game> queryWrapperaway = new QueryWrapper<>();
        queryWrapperhome.eq(leagueId!=null,"league_id",leagueId);
        queryWrapperaway.eq(leagueId!=null,"league_id",leagueId);
        Player player=playerService.getById(playerId);
        queryWrapperhome.eq("home_team",player.getTeamId());
        queryWrapperaway.eq("away_team",player.getTeamId());
        List<Game> homegameList = gameService.list(queryWrapperhome);
        List<Game> awaygameList = gameService.list(queryWrapperaway);
        List<Game> gameListall = new ArrayList<>();
        gameListall.addAll(homegameList);
        gameListall.addAll(awaygameList);
        System.err.println(gameListall);
        gameListall.forEach(game->{
            QueryWrapper<PlayerDataSingle> queryWrapperpds = new QueryWrapper<>();
            QueryWrapper<GameData> queryWrappergd = new QueryWrapper<>();
            queryWrappergd.eq(game.getId()!=null,"game_id",game.getId());
            game.setGameData(gameDataService.getOne(queryWrappergd));
            game.setLeague(leagueService.getById(game.getLeagueId()));
            game.setHometeaminfo(teamService.getById(game.getHomeTeam()));
            game.setAwayteaminfo(teamService.getById(game.getAwayTeam()));
            queryWrapperpds.eq("player_id",playerId);
            queryWrapperpds.eq("game_id",game.getId());
            game.setPlayerDataSingle(playerDataSingleService.getOne(queryWrapperpds));
        });
        gameListall.sort(Comparator.comparing(Game::getGameTime).reversed());
        return Result.success(gameListall);
    }
}

